﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using  DBSystem.BussinesEntities;

namespace DBSystem.Repository
{
    public class ClienteRepository:MasterRepository,IClienteRepository
    {
        public IEnumerable<Cliente> GetClientesByCriterio(string criterio)
        {
            var query = from c in Context.Clientes
                select c;

            if (!string.IsNullOrEmpty(criterio))
                query = from c in query
                    where c.rucDni.StartsWith(criterio) ||
                          c.razonSocial.ToUpper().Contains(criterio.ToUpper())
                    select c;

            return query;
        }

        public Cliente GetClienteByRucDni(string rucDni)
        {
            return Context.Clientes.SingleOrDefault(c => c.rucDni.Equals(rucDni));
        }


        public void AddCliente(Cliente cliente)
        {
            Context.Clientes.Add(cliente);
            Context.SaveChanges();
        }


        public Cliente GetClienteById(int id)
        {
            return Context.Clientes.SingleOrDefault(c => c.id.Equals(id));
        }
    }
}
